package com.cyzy.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface TimetableMapper {
    @Select({
            "SELECT ",
            "  u.user_id, u.user_name, ",
            "  IFNULL(cl.class_name, '无班级数据') AS class_name, ",
            "  IFNULL(c.course_name, '无课程数据') AS course_name, ",
            "  IFNULL(c.course_type, '无') AS course_type, ",
            "  IFNULL(c.campus_id, 0) AS campus_id, ",
            "  IFNULL(cs.class_id, '无安排') AS schedule_class_id, ",
            "  IFNULL(cs.class_room, '无') AS class_room, ",
            "  IFNULL(cs.start_time, '00:00:00') AS start_time, ",
            "  IFNULL(cs.end_time, '00:00:00') AS end_time, ",
            "  IFNULL(cs.weekday, '0') AS weekday ",
            "FROM user u ",
            "LEFT JOIN class_schedule cs ON u.user_id = cs.user_id ",
            "LEFT JOIN class cl ON cs.class_id = cl.class_id ",
            "LEFT JOIN course c ON cl.course_id = c.course_id ",
            "WHERE u.user_id = #{teacherId} ",
            "ORDER BY cs.weekday, cs.start_time"
    })
    List<Map<String, Object>> selectTimetableByTeacherId(@Param("teacherId") Integer teacherId);
}